/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package it.lapomuge.db.dao;

import it.lapomuge.db.entity.Giudice;

import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.Query;

/**
 *
 * @author Muge
 */
public class DbManagerUtenti extends DbManager {

    private DbManagerUtenti() {
    }

    public static DbManagerUtenti getInstance() {
        return new DbManagerUtenti();
    }

    public Giudice findbByUserPwd(String nome, String password) {
        EntityManager em = this.getEntityManager();

        Query q = null;
        try {
            q = em.createQuery("select c from " + getTableName(Giudice.class) + " c where c.login = :login and c.password = :pwd");
            q.setParameter("login", nome);
            q.setParameter("pwd", password);

            return (Giudice) q.getSingleResult();

        } catch (NoResultException ex) {
            return null;
        }
    }
    
    
    public static void main(String[] args){
        Giudice findbByUserPwd = DbManagerUtenti.getInstance().findbByUserPwd("andrea", "muge10");
        System.out.println(findbByUserPwd);
    }
}
